package com.cserver.springcloud.test;

import java.util.ArrayList;
import java.util.List;

public class BlockQueue {

    public static void main(String[] args) throws InterruptedException {
        BlockQueue blockQueue=new BlockQueue();
        System.out.println(blockQueue.pop());
        blockQueue.put("St");
    }

    private List list=new ArrayList();
    public synchronized Object pop() throws InterruptedException {
        while(list.size() == 0){
            this.wait();
        }
        if(list.size() >0){
            return list.remove(0);
        }else{
            return null;
        }
    }

    public synchronized void put(Object o){
        list.add(o);
        this.notify();
    }


}
